const exam = {
    state: {
        exams: [],
        nextIncrementIndex: 1,
    },
    mutations: {
        initial(state, { initialExamArr }) {
            state.exams = initialExamArr.reverse().map((e, i) => {
                return {
                    ...e,
                    examId: i,
                    name: e.title
                }
            }).reverse()
            state.nextIncrementIndex = initialExamArr.length
        },
        create(state, { createExam }) {
            state.exams.splice(0, 0, {
                examId: state.nextIncrementIndex,
                ...createExam
            })
            state.nextIncrementIndex += 1
        }
    },
    getters: {
        isEmpty: state => state.exams.length === 0,
        queryAll: state => state.exams
    }
}

export default exam